#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int N = 2010;


ll qui(ll a, ll b)
{
    ll res = 1;
    while (b)
    {
        if (b & 1)
            res = res * a % MOD;
        b >>= 1;
        a = a * a % MOD;
    }
    return res;
}


void solve()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<ll> pre(n + 1);
    for(int i = 0; i < n; i++) {
        pre[i + 1] = pre[i] + a[i];
    }
    ll t = (n * (n - 1)) / 2;
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        ans = (ans + a[i] * ((pre[i + 1] - a[i]) % MOD)) % MOD;
    }
    cout << (ans * qui(t % MOD, MOD - 2)) % MOD << endl;
}

int main()
{
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}